package com.jeeplus.test.jlnu.xlsxManage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.test.jlnu.xlsxManage.domain.entity.JlnuXlsxManage;
import com.jeeplus.test.jlnu.xlsxManage.domain.query.XlsxManagePageQuery;
import com.jeeplus.test.jlnu.xlsxManage.domain.query.XlsxManageQuery;
import com.jeeplus.test.jlnu.xlsxManage.service.JlnuXlsxManageService;
import com.jeeplus.test.tools.resp.R;
import com.jeeplus.test.tools.utils.PaginationUtil;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 动态表头(JlnuXlsxManage)表控制层
 *
 * @author ChiHongYu
 * @since 2025-02-17 15:16:26
 */
@Api(tags = "动态表头接口")
@Slf4j
@RestController
@RequestMapping("xlsxManage")
public class JlnuXlsxManageController {

    @Resource
    private JlnuXlsxManageService jlnuXlsxManageService;


    @ApiOperation("创建|修改")
    @PostMapping("insertOrUpdate")
    public R create(@RequestBody XlsxManageQuery param) {
        boolean opResult = this.jlnuXlsxManageService.insertOrUpdate(param);
        if (opResult) {
            return R.suc();
        } else {
            return R.error().setMsg("创建失败，请联系管理员");
        }
    }


    @ApiOperation("查询详情")
    @GetMapping("get")
    public R get(@RequestParam("id") Integer id) {
        JlnuXlsxManage jlnuXlsxManage = this.jlnuXlsxManageService.queryById(id);
        return R.suc(jlnuXlsxManage);
    }

    @ApiOperation("查询详情")
    @GetMapping("queryByType")
    public R queryByType(@RequestParam("type") String type, @RequestParam("officeId") String officeId, @RequestParam("name") String name) {
        JlnuXlsxManage jlnuXlsxManage = this.jlnuXlsxManageService.queryByType(type,officeId);
        return R.suc(jlnuXlsxManage);
    }



    @ApiOperation("查询详情")
    @GetMapping("getByOffice")
    public R getByOffice(@RequestParam("officeId") String officeId,
                         @RequestParam("type") String type,
                         @RequestParam("name") String name) {
        JlnuXlsxManage jlnuXlsxManage = this.jlnuXlsxManageService.getByOffice(officeId, type, name);
        return R.suc(jlnuXlsxManage);
    }

    @ApiOperation("分页查询")
    @GetMapping("page")
    public HashMap<String, Object> page(XlsxManagePageQuery param) {
        return jlnuXlsxManageService.page(param, PaginationUtil.convertToMySQLPagination(param.getPage(), param.getLimit()));
    }

    @ApiOperation("获取列表")
    @GetMapping("getList")
    public HashMap<String, Object> getList(XlsxManagePageQuery param) {
        return jlnuXlsxManageService.getList(param);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = true, dataType = "String", paramType = "query")
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "接口返回成功状态"),
            @ApiResponse(code = 201, message = "接口返回失败状态"),
            @ApiResponse(code = 500, message = "接口返回未知错误，请联系开发人员调试")
    })
    @ApiOperation(value = "删除", notes = "访问此接口，返回操作结果")
    @GetMapping("del")
    public R del(@RequestParam int id) {
        boolean opResult = this.jlnuXlsxManageService.deleteById(id);
        if (opResult) {
            return R.suc();
        } else {
            return R.error();
        }
    }

}
